﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GoToMarket : MonoBehaviour {
    public bool ToMarket = false;
    public UILabel Market;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    //跳转到指定应用商店，这里以小米为例
    public void OnRateToHuawei()
    {
        if( ToMarket )
        {
            RateToOther( "com.htdw.qmayh", "com.xiaomi.market" );
        }
        else
        {
            Market.gameObject.SetActive( true );
        }
       
    }
    public static void RateToOther( string appPkg, string marketPkg )
    {
        if( !Application.isEditor )
        {
            AndroidJavaClass intentClass = new AndroidJavaClass( "android.content.Intent" );
            AndroidJavaObject intentObject = new AndroidJavaObject( "android.content.Intent" );
            intentObject.Call<AndroidJavaObject>( "setAction", intentClass.GetStatic<string>( "ACTION_VIEW" ) );
            AndroidJavaClass uriClass = new AndroidJavaClass( "android.net.Uri" );
            AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>( "parse", "market://details?id=" + appPkg );
            intentObject.Call<AndroidJavaObject>( "setData", uriObject );
            intentObject.Call<AndroidJavaObject>( "setPackage",marketPkg );
            AndroidJavaClass unity = new AndroidJavaClass( "com.unity3d.player.UnityPlayer" );
            AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>( "currentActivity" );
            currentActivity.Call( "startActivity", intentObject );
        }
    }

}
